<template>
	<view class='search' >
		<view :style="{
			'padding-top':header_top+'px',
			'padding-bottom':header_top+'px'
		}">
			<!-- #ifdef H5 -->
			<view class="app-download" v-if="showDownload">
				<view class="close" @click="showDownload=false">×</view>
				<view class="logo">
					<image :src="downloadData.logo" style="width:60rpx;height:60rpx;"></image>
				</view>
				<view class="main-content" style="font-weight: 700;">
					<view>{{downloadData.title}}</view>
					<view>{{downloadData.content}}</view>
				</view>
				<view class="button" @click="goWeb(downloadData.url)">{{$t('search.open')}}</view>
			</view>
			<!-- #endif -->
			<view class="pageHead dFlex jBetween_aCenter" style="padding:10px 12px 15px;">
				<view @click="goHome">
					<image src="@/static/images/logo.png" style="width:60rpx;height:60rpx;margin-right: 20rpx;">
					</image>
				</view>
				<u-search :placeholder="$t('search.placeholder1')" @custom='searchShop' @search='searchShop'
					v-model='keyword' @focus='goKind()' bgColor='#ffffff' borderColor='#c6ccdd' shape='square'
					:showAction='false'></u-search>
				<view class="like" @click='lookWishList'>
					<u-icon name="../static/images/xinyuan.png" height="25px" width="25px"></u-icon>
				</view>
			</view>
		</view>
		<!-- 登录弹窗 -->
		<u-popup :show="loginDialog" mode="center">
			<login v-if='loginDialog' @close='closeLogin'></login>
		</u-popup>
	</view>
</template>

<script>
	import login from './login.vue';
	export default {
		name: "search",
		components: {
			login,
		},
		props: {
			showDownload: {
				type: Boolean,
				default: false
			},
			downloadData: {
				type: Object,
				default: function() {
					return {}
				}
			}
		},
		data() {
			return {
				header_top: 0,
				//header_top: getApp().globalData.header_top,
				header_height: getApp().globalData.header_height,
				keyword: '', //搜索关键字
				token: '',
				loginDialog: false,
			};
		},
		onShow() {
			console.log(1);
			console.log(this.$cache);
		},
		methods: {
			// 判断不是商品列表页跳商品列表 是商品列表就搜索
			goKind() {
				let curPage = getCurrentPages();
				let route = curPage[curPage.length - 1].route;
				if (route.indexOf('shopList') < 0) {
					uni.navigateTo({
						url: "/pages/shopList"
					})
				}
			},
			// 查看愿望清单
			lookWishList() {
				/*没登录出登录弹窗,登录就跳清单列表*/
				// this.loginDialog = true;
				uni.navigateTo({
					url: '/pages/wishList'
				})
			},
			// 搜索商品
			searchShop() {
				uni.navigateTo({
					url: '/pages/shopList?keyword=' + this.keyword
				})
			},
			closeLogin() {
				this.loginDialog = false;
			},
			goHome() {
				uni.switchTab({
					url: '/pages/home'
				})
			},
			goWeb(url) {
				// uni.navigateTo({
				// 	url: '/pages/webview?weburl=' + encodeURIComponent(url)
				// })
				window.open(url, '_blank');
			}
		}
	}
</script>

<style lang="scss" scoped>
	.search {
		background: white;
	}

	.pageHead {
		width: 100%;

		.logo {
			width: 35px;
			height: 35px;
			margin-right: 12px;
		}

		.like {
			width: 30px;
			height: 25px;
			margin-left: 10px;
			text-align: center;
			line-height: 24px;
		}
	}

	.app-download {
		background-color: $main;
		margin-bottom: 10rpx;
		width: 100vw;
		height: 120rpx;
		display: flex;
		align-items: center;
		color: #000000;

		.close {
			font-size: 50rpx;
			font-weight: 700;
			padding: 0 20rpx;
		}

		.logo {
			margin-right: 20rpx;
		}

		.main-content {
			flex: 1;
			font-size: 24rpx;
		}

		.button {
			margin: 20rpx;
			background-color: #ffff00;
			color: #000;
			font-size: 26rpx;
			font-weight: 700;
			padding: 10rpx 20rpx;
			border-radius: 10rpx;
		}
	}
</style>